package org.gitos.cloud.comet.mq;

import com.alibaba.fastjson.JSON;
import org.gitos.cloud.domain.comm.Constant;
import org.gitos.cloud.domain.mq.MqTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;

/**
 * Created by shizhengchu on 15/12/10. 所有的comet收到的消息往push_exchange推送
 */
@Component
@Configurable
public class PushManager {

    private static final Logger log = LoggerFactory
            .getLogger(PushManager.class);

    @Autowired
    private AmqpAdmin rabbitAdmin;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(String routeKey, Object obj) {
        MqTools.bindDirect(routeKey, Constant.SEVER_EXCHANGE, rabbitAdmin);
        rabbitTemplate.convertAndSend(Constant.SEVER_EXCHANGE, routeKey,
                JSON.toJSONString(obj));
    }


}
